&ANALYZE-SUSPEND _VERSION-NUMBER AB_v10r12 GUI adm2
&ANALYZE-RESUME
&Scoped-define WINDOW-NAME CURRENT-WINDOW


/* Temp-Table and Buffer definitions                                    */
DEFINE TEMP-TABLE ab_unmap
       FIELD alang AS CHARACTER FORMAT "X(256)":U 
       FIELD article_bas AS CHARACTER FORMAT "X(256)":U 
       FIELD article_ent AS CHARACTER FORMAT "X(256)":U 
       FIELD article_sais AS CHARACTER FORMAT "X(256)":U 
       FIELD Err_date AS CHARACTER FORMAT "X(256)":U 
       FIELD Err_deci AS CHARACTER FORMAT "X(256)":U 
       FIELD lablien2 AS CHARACTER FORMAT "X(256)":U 
       FIELD lablien3 AS CHARACTER FORMAT "X(256)":U 
       FIELD monnaie_doc AS CHARACTER FORMAT "X(256)":U 
       FIELD navigue AS CHARACTER FORMAT "X(256)":U 
       FIELD par-id AS CHARACTER FORMAT "X(256)":U 
       FIELD par-nosui AS CHARACTER FORMAT "X(256)":U 
       FIELD par-retour AS CHARACTER FORMAT "X(256)":U 
       FIELD prog_suivant AS CHARACTER FORMAT "X(256)":U 
       FIELD refd AS CHARACTER FORMAT "X(256)":U 
       FIELD refs AS CHARACTER FORMAT "X(256)":U .



&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS w-html 
/*------------------------------------------------------------------------

  File:

  Description:

  Input Parameters:
      <none>

  Output Parameters:
      <none>

  Author:

  Created:

------------------------------------------------------------------------*/
/*           This .W file was created with AppBuilder.                  */
/*----------------------------------------------------------------------*/

/* Create an unnamed pool to store all the widgets created
     by this procedure. This is a good default which assures
     that this procedure's triggers and internal procedures
     will execute in this procedure's storage, and that proper
     cleanup will occur on deletion of the procedure. */
CREATE WIDGET-POOL.

/* ***************************  Definitions  ************************** */

/* Preprocessor Definitions ---                                         */

/* Parameters Definitions ---                                           */

/* Local Variable Definitions ---                                       */

DEF NEW SHARED BUFFER doce     FOR doce.
DEF NEW SHARED BUFFER docld    FOR docld.
DEF            BUFFER wk-doce  FOR doce.

DEF NEW SHARED VAR a-lang          AS    INTEGER                   NO-UNDO.
DEF            VAR nb-ligne        AS    INTEGER                   NO-UNDO.
DEF            VAR i               AS    INTEGER                   NO-UNDO.
DEF            VAR j               AS    INTEGER                   NO-UNDO.
DEF            VAR nomprg          AS    CHARACTER                 NO-UNDO.
DEF            VAR lab-bouton      AS    CHARACTER EXTENT 5        NO-UNDO.
DEF            VAR action          AS    CHARACTER                 NO-UNDO.

DEF            VAR buf-nocli       LIKE doce.noadrf                NO-UNDO.
DEF            VAR buf-csmt        LIKE doce.csmtf                 NO-UNDO.
DEF            VAR buf-prefix      LIKE doce.prefix                NO-UNDO.
DEF            VAR buf-nodoc       LIKE doce.nodoc                 NO-UNDO.
DEF            VAR buf-rabais      LIKE docld.rabais               NO-UNDO.
DEF            VAR cde-prefix      LIKE doce.prefix                NO-UNDO.


DEF            VAR buf-pumb         LIKE docld.punite NO-UNDO.
DEF            VAR buf-punite       LIKE docld.punite NO-UNDO.
DEF            VAR buf-unitp        LIKE docld.unitp  NO-UNDO.
DEF            VAR buf-nocpt        LIKE docld.nocpt  NO-UNDO.
DEF            VAR buf-taxi         LIKE docld.taxi   NO-UNDO.

DEF            VAR flag-art        AS   LOGICAL                    NO-UNDO.
DEF            VAR flag-rem        AS   LOGICAL                    NO-UNDO.
DEF            VAR flag-lgdoc      AS   LOGICAL                    NO-UNDO.
DEF            VAR flag-affrab     AS   LOGICAL                    NO-UNDO.

DEF            VAR buf-qte         AS   INTEGER             NO-UNDO.
DEF            VAR buf-ref         AS   CHARACTER           NO-UNDO.
DEF            VAR buf-psuivant    AS   CHARACTER           NO-UNDO.

DEF NEW SHARED VAR nomchamp        AS CHARACTER EXTENT 2
                   INIT ["ref","qte"] NO-UNDO.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 

/* ********************  Preprocessor Definitions  ******************** */

&Scoped-define PROCEDURE-TYPE Web-Object
&Scoped-define DB-AWARE no

&Scoped-define WEB-FILE tbr_commande.htm

/* Name of designated FRAME-NAME and/or first browse and/or first query */
&Scoped-define FRAME-NAME Web-Frame

/* Standard List Definitions                                            */
&Scoped-Define ENABLED-OBJECTS ab_unmap.refd ab_unmap.prog_suivant ~
ab_unmap.alang ab_unmap.monnaie_doc ab_unmap.article_bas ~
ab_unmap.article_ent ab_unmap.par-retour ab_unmap.lablien2 ~
ab_unmap.lablien3 ab_unmap.refs ab_unmap.article_sais ab_unmap.par-id ~
ab_unmap.par-nosui ab_unmap.Err_date ab_unmap.Err_deci ab_unmap.navigue 
&Scoped-Define DISPLAYED-OBJECTS ab_unmap.refd ab_unmap.prog_suivant ~
ab_unmap.alang ab_unmap.monnaie_doc ab_unmap.article_bas ~
ab_unmap.article_ent ab_unmap.par-retour ab_unmap.lablien2 ~
ab_unmap.lablien3 ab_unmap.refs ab_unmap.article_sais ab_unmap.par-id ~
ab_unmap.par-nosui ab_unmap.Err_date ab_unmap.Err_deci ab_unmap.navigue 

/* Custom List Definitions                                              */
/* List-1,List-2,List-3,List-4,List-5,List-6                            */

/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME



/* ***********************  Control Definitions  ********************** */


/* Definitions of the field level widgets                               */

/* ************************  Frame Definitions  *********************** */

DEFINE FRAME Web-Frame
     ab_unmap.refd AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.prog_suivant AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.alang AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.monnaie_doc AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.article_bas AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.article_ent AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.par-retour AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.lablien2 AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.lablien3 AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.refs AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.article_sais AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.par-id AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.par-nosui AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.Err_date AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.Err_deci AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
     ab_unmap.navigue AT ROW 1 COL 1 HELP
          "" NO-LABEL FORMAT "X(256)":U
          VIEW-AS FILL-IN 
          SIZE 20 BY 1
    WITH 1 DOWN KEEP-TAB-ORDER OVERLAY 
         SIDE-LABELS 
         AT COL 1 ROW 1
         SIZE 57.63 BY 14.13.


/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
   Type: Web-Object
   Allow: Query
   Frames: 1
   Add Fields to: Neither
   Editing: Special-Events-Only
   Events: web.output,web.input
   Other Settings: COMPILE
   Temp-Tables and Buffers:
      TABLE: ab_unmap W "?" ?  
      ADDITIONAL-FIELDS:
          FIELD alang AS CHARACTER FORMAT "X(256)":U 
          FIELD article_bas AS CHARACTER FORMAT "X(256)":U 
          FIELD article_ent AS CHARACTER FORMAT "X(256)":U 
          FIELD article_sais AS CHARACTER FORMAT "X(256)":U 
          FIELD Err_date AS CHARACTER FORMAT "X(256)":U 
          FIELD Err_deci AS CHARACTER FORMAT "X(256)":U 
          FIELD lablien2 AS CHARACTER FORMAT "X(256)":U 
          FIELD lablien3 AS CHARACTER FORMAT "X(256)":U 
          FIELD monnaie_doc AS CHARACTER FORMAT "X(256)":U 
          FIELD navigue AS CHARACTER FORMAT "X(256)":U 
          FIELD par-id AS CHARACTER FORMAT "X(256)":U 
          FIELD par-nosui AS CHARACTER FORMAT "X(256)":U 
          FIELD par-retour AS CHARACTER FORMAT "X(256)":U 
          FIELD prog_suivant AS CHARACTER FORMAT "X(256)":U 
          FIELD refd AS CHARACTER FORMAT "X(256)":U 
          FIELD refs AS CHARACTER FORMAT "X(256)":U 
      END-FIELDS.
   END-TABLES.
 */
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB) 
  CREATE WINDOW w-html ASSIGN
         HEIGHT             = 14.13
         WIDTH              = 57.63.
/* END WINDOW DEFINITION */
                                                                        */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB w-html 
/* *********************** Included-Libraries ************************* */

{src/web2/html-map.i}

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME




/* ***********  Runtime Attributes and AppBuilder Settings  *********** */

&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR WINDOW w-html
  VISIBLE,,RUN-PERSISTENT                                               */
/* SETTINGS FOR FRAME Web-Frame
   FRAME-NAME UNDERLINE                                                 */
/* SETTINGS FOR FILL-IN ab_unmap.alang IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.article_bas IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.article_ent IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.article_sais IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.Err_date IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.Err_deci IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.lablien2 IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.lablien3 IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.monnaie_doc IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.navigue IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.par-id IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.par-nosui IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.par-retour IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.prog_suivant IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.refd IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* SETTINGS FOR FILL-IN ab_unmap.refs IN FRAME Web-Frame
   ALIGN-L EXP-LABEL EXP-FORMAT EXP-HELP                                */
/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME

 



/* ************************  Control Triggers  ************************ */

&Scoped-define SELF-NAME ab_unmap.article_bas
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.article_bas w-html WEB.output
PROCEDURE ab_unmap.article_bas.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  DEF VAR nom_page        AS    CHARACTER         NO-UNDO.
  DEF VAR ligne           AS    CHARACTER         NO-UNDO.
  DEF VAR lst-tag         AS    CHARACTER         NO-UNDO.
  DEF VAR pos             AS    INTEGER           NO-UNDO.
  DEF VAR txt_aff         AS    CHARACTER         NO-UNDO.

  DO WITH FRAME {&FRAME-NAME}:
  
      IF NOT flag-lgdoc THEN RETURN.

      txt_aff = "".

      FIND erreur WHERE erreur.noerr = 101057
                    AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
      txt_aff = txt_aff + IF NOT AVAILABLE erreur THEN "&nbsp;"
                          ELSE erreur.libel.

      FIND erreur WHERE erreur.noerr = 101012
                    AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
      txt_aff = txt_aff + "#" + erreur.libel
              + "#" + STRING(doce.totme - doce.totqte - doce.totmtn + doce.totme ,"->>>,>>9.99").
      
      FIND erreur WHERE erreur.noerr = 101058
                    AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
      txt_aff = txt_aff + "#" + IF NOT AVAILABLE erreur THEN "&nbsp;"
                          ELSE erreur.libel.     
      
      FIND erreur WHERE erreur.noerr = 101014
                    AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
      txt_aff = txt_aff + "#" + erreur.libel
              + "#" + STRING(doce.totqte + doce.totmtn - doce.totme,"->>>,>>9.99").
      
      FIND erreur WHERE erreur.noerr = 101059
                    AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
      txt_aff = txt_aff + "#" + IF NOT AVAILABLE erreur THEN "&nbsp;"
                          ELSE erreur.libel.

      FIND erreur WHERE erreur.noerr = 101013
                    AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
      txt_aff = txt_aff + "#" + erreur.libel
              + "#" + STRING(doce.totme,"->>>,>>9.99").

      txt_aff = txt_aff + "#" + doce.codmon.


      nom_page = IF flag-affrab THEN SEARCH("tbr_commande_bas.htm")
                 ELSE SEARCH("tbr_commande_bas_srab.htm").
      IF nom_page = ? THEN RETURN.
      INPUT FROM VALUE(nom_page).
      REPEAT:
         IMPORT UNFORMATTED ligne.
         pos = INDEX(ligne,"<!--WSTAG").
         IF TRIM(ligne) BEGINS "<!--" AND pos = 0 THEN NEXT.
         IF pos = 0 THEN {&out} ligne SKIP.
         ELSE DO:
            RUN decode_tag(ligne,"champ",OUTPUT lst-tag).
            DO i = 1 TO NUM-ENTRIES(lst-tag).
               RUN remplace_tag ("champ",10,ENTRY(i,lst-tag),txt_aff,INPUT-OUTPUT ligne).
            END.
            {&out} ligne SKIP.
         END.
      END.
  END.
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.article_ent
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.article_ent w-html WEB.output
PROCEDURE ab_unmap.article_ent.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  DEF VAR nom_page        AS CHARACTER      NO-UNDO.
  DEF VAR ligne           AS CHARACTER      NO-UNDO.
  DEF VAR lst-tag         AS CHARACTER      NO-UNDO.
  DEF VAR pos             AS INTEGER        NO-UNDO.
  DEF VAR nb              AS INTEGER        NO-UNDO.
  DEF VAR buf-mess        AS CHARACTER      NO-UNDO.
  
  DO WITH FRAME {&FRAME-NAME}:
  
      buf-mess = "".

      IF NOT flag-lgdoc THEN DO:
         FIND erreur WHERE erreur.noerr = 101054
                       AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
         IF AVAILABLE erreur THEN buf-mess = buf-mess + erreur.libel.
         nom_page = SEARCH("tbr_commande_vide.htm").
      END.
      ELSE DO:
         IF flag-affrab THEN FIND erreur WHERE erreur.noerr = 101009
                                           AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
         ELSE FIND erreur WHERE erreur.noerr = 101184
                            AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
         IF AVAILABLE erreur THEN buf-mess = buf-mess + erreur.libel.
         nom_page = IF flag-affrab THEN SEARCH("tbr_commande_entete.htm")
                    ELSE SEARCH("tbr_commande_entete_srab.htm").

         IF flag-lgdoc AND (doce.noadrf = 1000 OR doce.noadrf = 1001) THEN DO:
            FIND erreur WHERE erreur.noerr = 101055
                           AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
            buf-mess = buf-mess + "#" + ENTRY(1,erreur.libel,"#").

            buf-mess = buf-mess + "#" + "<input name=~"monnaie~" type=~"radio~" value=~"CHF~" onClick=~"document.commande.submit();~"".
            IF doce.codmon = "CHF" THEN  buf-mess = buf-mess + " checked=~"checked~"".

            buf-mess = buf-mess + ">".
            buf-mess = buf-mess + "#" + ENTRY(2,erreur.libel,"#").

            buf-mess = buf-mess + "#" + "<input name=~"monnaie~" type=~"radio~" value=~"EUR~" onClick=~"document.commande.submit();~"".
            IF doce.codmon = "EUR" THEN  buf-mess = buf-mess + " checked=~"checked~"".
            buf-mess = buf-mess + ">".
         END.

      END.

      nb = NUM-ENTRIES(buf-mess,"#").

      IF nom_page = ? THEN RETURN.
      INPUT FROM VALUE(nom_page).
      REPEAT:
         IMPORT UNFORMATTED ligne.
         pos = INDEX(ligne,"<!--WSTAG").
         IF TRIM(ligne) BEGINS "<!--" AND pos = 0 THEN NEXT.
         IF pos = 0 THEN {&out} ligne SKIP.
         ELSE DO:
            RUN decode_tag(ligne,"label",OUTPUT lst-tag).
            DO i = 1 TO NUM-ENTRIES(lst-tag).
               RUN remplace_tag ("label",nb,ENTRY(i,lst-tag),buf-mess,INPUT-OUTPUT ligne).
            END.
            {&out} ligne SKIP.
         END.
      END.
  END.
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.article_sais
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.article_sais w-html WEB.output
PROCEDURE ab_unmap.article_sais.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.

  DEF VAR flag-trouve     AS    LOGICAL           NO-UNDO.
  DEF VAR txt_aff         AS    CHARACTER         NO-UNDO.
  DEF VAR nom_page        AS    CHARACTER         NO-UNDO.
  DEF VAR ligne           AS    CHARACTER         NO-UNDO.
  DEF VAR lst-tag         AS    CHARACTER         NO-UNDO.
  DEF VAR pos             AS    INTEGER           NO-UNDO.
  DEF VAR i               AS    INTEGER           NO-UNDO.
  DEF VAR num             AS    INTEGER           NO-UNDO.
  
  FOR EACH docld WHERE docld.nosoc  = doce.nosoc
                   AND docld.typdoc = doce.typdoc
                   AND docld.prefix = doce.prefix
                   AND docld.nodoc  = doce.nodoc NO-LOCK:

      IF docld.ref = "" AND docld.norub = "" THEN NEXT.

      IF docld.norub <> "" THEN DO:
         FIND FIRST docli WHERE docli.nosoc  = docld.nosoc
                            AND docli.typdoc = docld.typdoc
                            AND docli.prefix = docld.prefix
                            AND docli.nodoc  = docld.nodoc
                            AND docli.noseq  = docld.noseq NO-LOCK NO-ERROR.

          txt_aff = "#" + IF AVAILABLE docli THEN docli.libel ELSE "".
          txt_aff = txt_aff + "#" + STRING(docld.montne,"zzz,zz9.99").
          txt_aff = txt_aff + "#" + doce.codmon + "#".

          nom_page = IF flag-affrab THEN SEARCH("tbr_commande_ligne_rub.htm")
                     ELSE SEARCH("tbr_commande_ligne_rub_srab.htm").
          IF nom_page = ? THEN RETURN.
          INPUT FROM VALUE(nom_page).
          REPEAT:
             IMPORT UNFORMATTED ligne.
             pos = INDEX(ligne,"<!--WSTAG").
             IF TRIM(ligne) BEGINS "<!--" AND pos = 0 THEN NEXT.
             IF pos = 0 THEN {&out} ligne SKIP.
             ELSE DO:
                RUN decode_tag(ligne,"champ",OUTPUT lst-tag).
                DO i = 1 TO NUM-ENTRIES(lst-tag).
                   RUN remplace_tag ("champ",4,ENTRY(i,lst-tag),txt_aff,INPUT-OUTPUT ligne).
                END.
                {&out} ligne SKIP.
             END.
          END.

      END.
      ELSE DO:
          FIND arti WHERE arti.nosoc = docld.nosoc
                      AND arti.ref   = docld.ref NO-LOCK NO-ERROR.

          IF NOT AVAILABLE arti THEN NEXT.

          flag-art = TRUE.



    /*     txt_aff = "<a href=~"new.parvis.ch/cgi-bin/cgiip.exe/WService=wsbroker1/tbr_commande_delart.w?RowId=" + STRING(ROWID(docld))  */
    /*              + "&retour=" + IF a-lang = 1 THEN  "/de/warenkorb" ELSE "/fr/panier".                                                */
    /*     txt_aff = txt_aff + "~"><img border=~"0~" src=~"/images/annuler.gif~" /></a>".                                                */
    /*     txt_aff = txt_aff + "#" + "<input type=~"text~" name=~"qtes" + STRING(docld.noseq)                                            */
    /*             + "~" value=~"" + STRING(docld.qtec) + "~" size=~"2~" onchange=~"return ctrlZone(this,3,'4');~""                      */
    /*             + " style=~"text-align: right~" />".                                                                                  */

          txt_aff = "<img border=~"0~" src=~"/images/annuler.gif~""
                  + " onClick=~"document.commande.refd.value = '" + STRING(ROWID(docld))
                  + "'; document.commande.submit();~" />".
          txt_aff = txt_aff + "#" + "<input type=~"text~" name=~"qtes" + STRING(docld.noseq)
                  + "~" value=~"" + STRING(docld.qtec) + "~" size=~"2~""
                  + " style=~"text-align: right~" />".

          txt_aff = txt_aff + "#" + arti.titre + "#" + arti.auteur + "#" + ENTRY(1,arti.DESCRIPTION,CHR(10)).
          txt_aff = txt_aff + "#" + STRING(docld.punite,"zz,zz9.99").
          IF flag-affrab THEN txt_aff = txt_aff + "#" + STRING(docld.rabais,"zz9.99 %").
          txt_aff = txt_aff + "#" + STRING(docld.montne,"zzz,zz9.99").
          txt_aff = txt_aff + "#" + doce.codmon + "#" + docld.ref.

          nom_page = IF flag-affrab THEN SEARCH("tbr_commande_ligne.htm")
                     ELSE SEARCH("tbr_commande_ligne_srab.htm").
          IF nom_page = ? THEN RETURN.
          INPUT FROM VALUE(nom_page).
          REPEAT:
             IMPORT UNFORMATTED ligne.
             pos = INDEX(ligne,"<!--WSTAG").
             IF TRIM(ligne) BEGINS "<!--" AND pos = 0 THEN NEXT.
             IF pos = 0 THEN {&out} ligne SKIP.
             ELSE DO:
                RUN decode_tag(ligne,"champ",OUTPUT lst-tag).
                DO i = 1 TO NUM-ENTRIES(lst-tag).
                   RUN remplace_tag ("champ",10,ENTRY(i,lst-tag),txt_aff,INPUT-OUTPUT ligne).
                END.
                {&out} ligne SKIP.
             END.
          END.
      END.
  END.
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.Err_deci
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.Err_deci w-html WEB.output
PROCEDURE ab_unmap.Err_deci.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  RUN aff_label (100089).
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.lablien2
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.lablien2 w-html WEB.output
PROCEDURE ab_unmap.lablien2.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  IF flag-art THEN DO:
     {&out} "<span class=~"continue~">".
                RUN bouton.r (101001,a-lang).
     {&out} "</span>".
  END.
  ELSE DO:
     {&out} "<div align=~"CENTER~">".
     RUN bouton.r (101001,a-lang).
     {&out} "</div>".
  END.

  END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.lablien3
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.lablien3 w-html WEB.output
PROCEDURE ab_unmap.lablien3.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  IF flag-art THEN RUN bouton.r (101095,a-lang).

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.navigue
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.navigue w-html WEB.output
PROCEDURE ab_unmap.navigue.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  IF flag-art THEN RUN bouton.r (101000,a-lang).
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME ab_unmap.prog_suivant
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL ab_unmap.prog_suivant w-html web.output
PROCEDURE ab_unmap.prog_suivant.output .
/*------------------------------------------------------------------------------
  Purpose:     Output the value of the field to the WEB stream
               in place of the HTML field definition.
  Parameters:  p-field-defn
  Notes:       
------------------------------------------------------------------------------*/
  DEFINE INPUT PARAMETER p-field-defn AS CHARACTER NO-UNDO.
  
  DO WITH FRAME {&FRAME-NAME}:
     IF REQUEST_METHOD = "POST":U AND buf-psuivant <> "" THEN DO:
        {&out} "" SKIP
               "".
        {&out} buf-psuivant.
        {&out} "" SKIP.
     END.
  END.
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&UNDEFINE SELF-NAME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK w-html 


/* ************************  Main Code Block  ************************* */

/* Standard Main Block that runs adm-create-objects, initializeObject
 * and process-web-request.
 * The bulk of the web processing is in the Procedure process-web-request
 * elsewhere in this Web object.
 */
{src/web2/template/hmapmain.i}

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* **********************  Internal Procedures  *********************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE adm-create-objects w-html  _ADM-CREATE-OBJECTS
PROCEDURE adm-create-objects :
/*------------------------------------------------------------------------------
  Purpose:     Create handles for all SmartObjects used in this procedure.
               After SmartObjects are initialized, then SmartLinks are added.
  Parameters:  <none>
------------------------------------------------------------------------------*/

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE aff_label w-html 
PROCEDURE aff_label :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

  DEF INPUT PARAMETER num  AS INTEGER NO-UNDO.

  FIND erreur WHERE erreur.noerr = num
                AND erreur.lang  = a-lang NO-LOCK NO-ERROR.

  IF AVAILABLE erreur THEN {&out} erreur.libel.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE calcul_mtligne w-html 
PROCEDURE calcul_mtligne :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/
{calcul_ligne.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE creation_ligne w-html 
PROCEDURE creation_ligne :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

{creation_ligne.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE decode_tag w-html 
PROCEDURE decode_tag :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

DEF INPUT  PARAMETER ligne    AS CHARACTER           NO-UNDO.
DEF INPUT  PARAMETER ancre    AS CHARACTER           NO-UNDO.
DEF OUTPUT PARAMETER lst-tag  AS CHARACTER           NO-UNDO.

DEF VAR i              AS INTEGER           NO-UNDO.
DEF VAR j              AS INTEGER           NO-UNDO.
DEF VAR pos            AS INTEGER           NO-UNDO.
DEF VAR tag            AS CHARACTER         NO-UNDO.

REPEAT:
   i = INDEX(ligne,"<!--").
   j = IF INDEX(ligne,"-->") <> 0 THEN INDEX(ligne,"-->") + 2 ELSE LENGTH(ligne).
   IF i = 0 THEN LEAVE.
   tag = SUBSTRING(ligne,i,j - i + 1).
   pos = INDEX(tag,"<!--WSTAG").
   IF pos <> 0 THEN DO:
      pos = INDEX(tag,ancre).
      IF pos <> 0 AND LOOKUP(tag,lst-tag) = 0 THEN lst-tag = lst-tag + "," + tag.
   END.
   ligne = SUBSTRING(ligne,j + 1).
END.
lst-tag = SUBSTRING(lst-tag,2).

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE htmOffsets w-html  _WEB-HTM-OFFSETS
PROCEDURE htmOffsets :
/*------------------------------------------------------------------------------
  Purpose:     Runs procedure to associate each HTML field with its
               corresponding widget name and handle.
  Parameters:  
  Notes:       
------------------------------------------------------------------------------*/
  RUN readOffsets ("{&WEB-FILE}":U).
  RUN htmAssociate
    ("article_bas":U,"ab_unmap.article_bas":U,ab_unmap.article_bas:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("article_ent":U,"ab_unmap.article_ent":U,ab_unmap.article_ent:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("article_sais":U,"ab_unmap.article_sais":U,ab_unmap.article_sais:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("Err_date":U,"ab_unmap.Err_date":U,ab_unmap.Err_date:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("Err_deci":U,"ab_unmap.Err_deci":U,ab_unmap.Err_deci:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("lablien2 --":U,"ab_unmap.lablien2":U,ab_unmap.lablien2:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("lablien3 --":U,"ab_unmap.lablien3":U,ab_unmap.lablien3:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("lang":U,"ab_unmap.alang":U,ab_unmap.alang:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("monnaie_doc":U,"ab_unmap.monnaie_doc":U,ab_unmap.monnaie_doc:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("navigue":U,"ab_unmap.navigue":U,ab_unmap.navigue:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("par-id":U,"ab_unmap.par-id":U,ab_unmap.par-id:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("par-nosui":U,"ab_unmap.par-nosui":U,ab_unmap.par-nosui:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("par-retour":U,"ab_unmap.par-retour":U,ab_unmap.par-retour:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("prog_suivant":U,"ab_unmap.prog_suivant":U,ab_unmap.prog_suivant:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("refd":U,"ab_unmap.refd":U,ab_unmap.refd:HANDLE IN FRAME {&FRAME-NAME}).
  RUN htmAssociate
    ("refs":U,"ab_unmap.refs":U,ab_unmap.refs:HANDLE IN FRAME {&FRAME-NAME}).
END PROCEDURE.


/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE modification_document w-html 
PROCEDURE modification_document :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/
DEF            VAR i             AS   INTEGER             NO-UNDO.
DEF            VAR j             AS   INTEGER             NO-UNDO.
DEF            VAR buf-qte       AS   INTEGER             NO-UNDO.
DEF            VAR buf-ref       AS   CHARACTER           NO-UNDO.
DEF            VAR buf-art       AS   CHARACTER           NO-UNDO.
DEF            VAR flag-monnaie  AS LOGICAL               NO-UNDO.

DO WITH FRAME {&FRAME-NAME}:
   {calcul_document.i}
END.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE outputHeader w-html 
PROCEDURE outputHeader :
/*------------------------------------------------------------------------
  Purpose:     Output the MIME header, and any "cookie" information needed
               by this procedure.  
  Parameters:  <none>
  Notes:       In the event that this Web object is state-aware, this is
               a good place to set the WebState and WebTimeout attributes.
------------------------------------------------------------------------*/

  /* To make this a state-aware Web object, pass in the timeout period
   * (in minutes) before running outputContentType.  If you supply a
   * timeout period greater than 0, the Web object becomes state-aware
   * and the following happens:
   *
   *   - 4GL variables webState and webTimeout are set
   *   - a cookie is created for the broker to id the client on the return trip
   *   - a cookie is created to id the correct procedure on the return trip
   *
   * If you supply a timeout period less than 1, the following happens:
   *
   *   - 4GL variables webState and webTimeout are set to an empty string
   *   - a cookie is killed for the broker to id the client on the return trip
   *   - a cookie is killed to id the correct procedure on the return trip
   *
   * For example, set the timeout period to 5 minutes.
   *
   *   setWebState (5.0).
   */
    
  /* Output additional cookie information here before running outputContentType.
   *   For more information about the Netscape Cookie Specification, see
   *   http://home.netscape.com/newsref/std/cookie_spec.html  
   *   
   *   Name         - name of the cookie
   *   Value        - value of the cookie
   *   Expires date - Date to expire (optional). See TODAY function.
   *   Expires time - Time to expire (optional). See TIME function.
   *   Path         - Override default URL path (optional)
   *   Domain       - Override default domain (optional)
   *   Secure       - "secure" or unknown (optional)
   *
   *   The following example sets custNum=23 and expires tomorrow at (about)
   *   the same time but only for secure (https) connections.
   *      
   *   RUN SetCookie IN web-utilities-hdl
   *     ("custNum":U, "23":U, TODAY + 1, TIME, ?, ?, "secure":U).
   */
  output-content-type ("text/html":U).
  
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE process-web-request w-html 
PROCEDURE process-web-request :
/*------------------------------------------------------------------------
  Purpose:     Process the web request.
  Notes:       
------------------------------------------------------------------------*/
       /* STEP 0 -
   * Output the MIME header and set up the object as state-less or state-aware.
   * This is required if any HTML is to be returned to the browser.
   *
   * NOTE: Move 'RUN outputHeader.' to the GET section below if you are going
   * to simulate another Web request by running a Web Object from this
   * procedure.  Running outputHeader precludes setting any additional cookie
   * information.
   */
   
  a-lang = INTEGER(get-field("lang")).
  IF a-lang = 0 THEN a-lang = 2.

  {client.i}
  
OUTPUT TO "/user/wrk/thesis.log" APPEND.
PUT UNFORMATTED string(NOW) "SessionId : " get-cookie("SessionId")  "-" REQUEST_METHOD buf-prefix buf-nodoc SKIP.
PUT "-------------------------------------" SKIP.
OUTPUT CLOSE.

  FIND doce WHERE doce.nosoc  = 1
              AND doce.typdoc = "PA"
              AND doce.prefix = buf-prefix
              AND doce.nodoc  = buf-nodoc NO-LOCK NO-ERROR.


  OUTPUT TO "/user/wrk/thesis.log" APPEND.
  PUT UNFORMATTED string(NOW) "avant creation document" "-"  buf-prefix buf-nodoc AVAILABLE doce SKIP.
  PUT "-------------------------------------" SKIP.
  OUTPUT CLOSE.

  IF buf-prefix = "" OR NOT AVAILABLE doce THEN DO:
     buf-prefix = "CAD".
/*      FIND FIRST doce WHERE doce.nosoc  = 1                                    */
/*                        AND doce.typdoc = "PA"                                 */
/*                        AND doce.prefix = "CAD"                                */
/*                        AND doce.nodoc  < 10000 NO-LOCK NO-ERROR.              */
/*      IF AVAILABLE doce AND doce.nodoc <> 1 THEN buf-nodoc  = doce.nodoc - 1.  */
/*      ELSE DO:                                                                 */
        FIND LAST doce WHERE doce.nosoc  = 1
                         AND doce.typdoc = "PA"
                         AND doce.prefix = "CAD"
                         NO-LOCK NO-ERROR.

        buf-nodoc  = IF AVAILABLE doce THEN doce.nodoc + 1 ELSE 1.
/*      END.  */
     CREATE doce.
     ASSIGN doce.nosoc  = 1
            doce.typdoc = "PA"
            doce.prefix = "CAD"
            doce.nodoc  = buf-nodoc
            doce.noadrf = IF buf-nocli = 0 THEN 1000 ELSE buf-nocli
            doce.csmtf  = 0
            doce.noadrl = IF buf-nocli = 0 THEN 1000 ELSE buf-nocli
            doce.csmtl  = 0
            doce.cours  = 1
            doce.unit   = 1
            doce.nodos  = 61
            doce.datdoc = TODAY
            doce.dval   = TODAY
            doce.ref    = STRING(TIME,"HH:MM").

     ASSIGN websession.valeur1 = doce.prefix
            websession.ordre   = doce.nodoc.

     FIND adrd WHERE adrd.nosoc = doce.nosoc
                 AND adrd.noadr = doce.noadrl
                 AND adrd.csmt  = doce.csmtl NO-LOCK NO-ERROR.

     doce.taux   = adrd.codicha.
     doce.codmon = adrd.codmon.

     IF adrd.adrfac <> 0 THEN ASSIGN doce.noadrf = adrd.adrfac
                                     doce.csmtf  = adrd.csmtfac.

     IF doce.noadrf <> 1001 THEN DO:
        FIND FIRST mon WHERE mon.nosoc  = doce.nosoc
               AND mon.codmon = doce.codmon
               AND mon.boucl  = ""
               AND mon.datc  <= doce.datdoc NO-LOCK NO-ERROR.
        IF AVAILABLE mon THEN ASSIGN doce.cours = mon.cours
                                     doce.unit  = mon.unit.
        ELSE ASSIGN doce.cours = 1
                    doce.unit  = 1.
     END.
     ELSE ASSIGN doce.cours = 1
                 doce.unit  = 1.

  END.

  FIND FIRST docld WHERE docld.nosoc  = doce.nosoc
                     AND docld.typdoc = doce.typdoc
                     AND docld.prefix = doce.prefix
                     AND docld.nodoc  = doce.nodoc
                     AND docld.rabais <> 0 NO-LOCK NO-ERROR.
  flag-affrab = AVAILABLE docld.

  RUN outputHeader.

  /* Describe whether to receive FORM input for all the fields.  For example,
   * check particular input fields (using GetField in web-utilities-hdl).
   * Here we look at REQUEST_METHOD.
   */
  IF REQUEST_METHOD = "POST":U THEN DO:
    /* STEP 1 -
     * Copy HTML input field values to the Progress form buffer. */
    RUN inputFields.

    /* STEP 2 -
     * Open the database or SDO query and and fetch the first record. */
    RUN findRecords.

    DO WITH FRAME {&FRAME-NAME}:

       IF get-field("par-id") <> "" THEN
          FIND doce WHERE ROWID(doce) = TO-ROWID(get-field("par-id")) NO-ERROR.

       FIND erreur WHERE erreur.noerr = 101000
                     AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
       lab-bouton[1] = ENTRY(1,erreur.libel).

       FIND erreur WHERE erreur.noerr = 101001
                     AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
       lab-bouton[2] = ENTRY(1,erreur.libel).

       FIND erreur WHERE erreur.noerr = 101095
                     AND erreur.lang  = a-lang NO-LOCK NO-ERROR.
       lab-bouton[3] = ENTRY(1,erreur.libel).

       action  = get-field("bouton").
       IF action = "" THEN action = lab-bouton[1].

       IF get-field("refd") <> "" THEN RUN suppression_ligne(get-field("refd")).

       RUN modification_document.

       FIND FIRST docld WHERE docld.nosoc  = doce.nosoc
                          AND docld.typdoc = doce.typdoc
                          AND docld.prefix = doce.prefix
                          AND docld.nodoc  = doce.nodoc
                          AND docld.rabais <> 0 NO-LOCK NO-ERROR.
       flag-affrab = AVAILABLE docld.

       FIND FIRST docld WHERE docld.nosoc  = doce.nosoc
                          AND docld.typdoc = doce.typdoc
                          AND docld.prefix = doce.prefix
                          AND docld.nodoc  = doce.nodoc
                          AND docld.ref   <> "" NO-LOCK NO-ERROR.
       
       flag-lgdoc = AVAILABLE docld.

    END.

    /* STEP 3 -
     * AssignFields will save the data in the frame.
     * (it automatically upgrades the lock to exclusive while doing the update)
     *
     *  If a new record needs to be created set AddMode to true before
        running assignFields.
     *     setAddMode(TRUE).
     * RUN assignFields. */

    /* STEP 4 -
     * Decide what HTML to return to the user. Choose STEP 4.1 to simulate
     * another Web request -OR- STEP 4.2 to return the original form (the
     * default action).
     *
     * STEP 4.1 -
     * To simulate another Web request, change the REQUEST_METHOD to GET
     * and RUN the Web object here.  For example,
     *
     *  ASSIGN REQUEST_METHOD = "GET":U.
     *  RUN run-web-object IN web-utilities-hdl ("myobject.w":U).
     */



    IF action = lab-bouton[2] THEN DO:
        buf-psuivant = get-field("par-retour").
/*                                                                            */
/*        ASSIGN REQUEST_METHOD = "GET":U.                                    */
/*        RUN run-web-object IN web-utilities-hdl (get-field("par-retour")).  */
/*        RETURN.                                                             */
    END.

    IF action = lab-bouton[3] THEN DO:

/*         IF buf-nocli = 0  OR buf-nocli = 10000 THEN                             */
/*            buf-psuivant = "tbr_commande_ident.w?lang=" + STRING(a-lang).        */
/*         ELSE RUN buf-psuivant ="tbr_commande_envoi.w?lang=" + STRING(a-lang)).  */

/*        ASSIGN REQUEST_METHOD = "GET":U.                                                               */
/*        IF buf-nocli = 0  OR buf-nocli = 10000 THEN                                                    */
/*           RUN run-web-object IN web-utilities-hdl ("tbr_commande_ident.w?lang=" + STRING(a-lang)).    */
/*        ELSE RUN run-web-object IN web-utilities-hdl ("tbr_commande_envoi.w?lang=" + STRING(a-lang)).  */
/*        RETURN.                                                                                        */

        IF buf-nocli = 0 OR buf-nocli = 10000 THEN
           buf-psuivant = IF a-lang = 1 THEN "identification_de|"
                            ELSE "identification_fr|128|".
        ELSE buf-psuivant = IF a-lang = 1 THEN "commande_envoi_de|"
                            ELSE "commande_envoi_fr|128|".

    END.

    /* STEP 4.2 -
     * To return the form again, set data values, display them, and output
     * them to the WEB stream.
     *
     * STEP 4.2a -
     * Set any values that need to be set, then display them. */
    RUN displayFields.

    /* STEP 4.2b -
     * Enable objects that should be enabled. */
    RUN enableFields.

    par-retour:SCREEN-VALUE = get-field("par-retour").
    par-id:SCREEN-VALUE = STRING(ROWID(doce)).
    refs:SCREEN-VALUE   = "".
    alang:SCREEN-VALUE   = STRING(a-lang).

    /* STEP 4.2c -
     * OUTPUT the Progress form buffer to the WEB stream. */
    RUN outputFields.

  END. /* Form has been submitted. */

  /* REQUEST-METHOD = GET */
  ELSE DO:
  
  
      OUTPUT TO "/user/wrk/creation.log" APPEND.
      PUT UNFORMATTED STRING(time,"HH:MM:SS") " Passage GET "  buf-nocli "-" buf-prefix "-" buf-nodoc SKIP.
      OUTPUT CLOSE.

    /* This is the first time that the form has been called. Just return the
     * form.  Move 'RUN outputHeader.' here if you are going to simulate
     * another Web request. */

/*     RUN outputHeader.  */

    /* STEP 1 -
     * Open the database or SDO query and and fetch the first record. */
    RUN findRecords.


    /* Return the form again. Set data values, display them, and output them
     * to the WEB stream.
     *
     * STEP 2a -
     * Set any values that need to be set, then display them. */
    RUN displayFields.

    /* STEP 2b -
     * Enable objects that should be enabled. */
    RUN enableFields.

    FIND doce WHERE doce.nosoc  = 1
                AND doce.typdoc = "PA"
                AND doce.prefix = buf-prefix
                AND doce.nodoc  = buf-nodoc NO-ERROR.

    FIND erreur WHERE erreur.noerr = 101033
                  AND erreur.lang  = a-lang NO-LOCK NO-ERROR.

    FIND FIRST docld WHERE docld.nosoc  = doce.nosoc
                       AND docld.typdoc = doce.typdoc
                       AND docld.prefix = doce.prefix
                       AND docld.nodoc  = doce.nodoc
                       AND docld.norub <> ""  NO-ERROR.
    IF AVAILABLE docld THEN DO:  
       FOR EACH docli WHERE docli.nosoc  = docld.nosoc
                        AND docli.typdoc = docld.typdoc
                        AND docli.prefix = docld.prefix
                        AND docli.nodoc  = docld.nodoc
                        AND docli.noseq  = docld.noseq:
           DELETE docli.
       END.
       doce.totmtn  = doce.totmtn  - docld.montne - IF docld.taxi THEN 0
                                                    ELSE docld.montx.
       doce.totqte  = doce.totqte - docld.montx.
       doce.totme   = doce.totmtn.
       doce.totmb   = doce.totme * doce.cours / doce.unit.
       DELETE docld.
    END.

    DO WITH FRAME {&FRAME-NAME}:
       par-id:SCREEN-VALUE = STRING(ROWID(doce)).
       refs:SCREEN-VALUE   = get-field("id").
       par-retour:SCREEN-VALUE = IF get-field("retour") = "" THEN
                                    IF flag-art THEN IF a-lang = 1 THEN "/de/warenkorb"
                                                     ELSE "/fr/panier"
                                    ELSE IF a-lang = 1 THEN "/de/buchhandlung"
                                         ELSE "/fr/librairie"
                                 ELSE get-field("retour").
       monnaie:SCREEN-VALUE = doce.codmon.
       alang:SCREEN-VALUE   = STRING(a-lang).

    END.

    ASSIGN buf-ref = get-field("id")
           buf-qte = 1.

    FIND FIRST docld WHERE docld.nosoc  = doce.nosoc
                       AND docld.typdoc  = doce.typdoc
                       AND docld.prefix  = doce.prefix
                       AND docld.nodoc   = doce.nodoc
                       AND docld.ref     = buf-ref  NO-ERROR.

    IF AVAILABLE docld THEN  DO:
       ASSIGN doce.totmtn = doce.totmtn - docld.montne
                          - IF docld.taxi THEN 0 ELSE docld.montx
              doce.totqte = doce.totqte - docld.montx.

       ASSIGN docld.qteumq = docld.qteumq + 1
              docld.qtec   = docld.qteumq
              docld.qteumb = docld.qtec
              docld.solde  = docld.qtec.

       RUN calcul_mtligne.
    END.
    ELSE DO:
       FIND LAST docld WHERE docld.nosoc  = doce.nosoc
                         AND docld.typdoc = doce.typdoc
                         AND docld.prefix = doce.prefix
                         AND docld.nodoc  = doce.nodoc NO-LOCK NO-ERROR.

       FIND arti WHERE arti.nosoc = doce.nosoc
                   AND arti.ref   = buf-ref  NO-LOCK NO-ERROR.

       IF buf-ref <> "" THEN RUN creation_ligne (buf-ref,buf-qte).
    END.

    FIND FIRST docld WHERE docld.nosoc  = doce.nosoc
                       AND docld.typdoc = doce.typdoc
                       AND docld.prefix = doce.prefix
                       AND docld.nodoc  = doce.nodoc
                       AND docld.ref   <> "" NO-LOCK NO-ERROR.
    flag-lgdoc = AVAILABLE docld.

    /* STEP 2c -
     * OUTPUT the Progress from buffer to the WEB stream. */
    RUN outputFields.

  END.
  
  /* Show error messages. */
  IF AnyMessage() THEN
  DO:
     /* ShowDataMessage may return a Progress column name. This means you
      * can use the function as a parameter to HTMLSetFocus instead of
      * calling it directly.  The first parameter is the form name.   
      *
      * HTMLSetFocus("document.DetailForm",ShowDataMessages()). */
     ShowDataMessages().
  END.
 
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE remplace_tag w-html 
PROCEDURE remplace_tag :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

DEF INPUT        PARAMETER ancre    AS   CHARACTER        NO-UNDO.       
DEF INPUT        PARAMETER nombre   AS   INTEGER          NO-UNDO.       
DEF INPUT        PARAMETER tag      AS   CHARACTER        NO-UNDO.       
DEF INPUT        PARAMETER texte    AS   CHARACTER        NO-UNDO.       
DEF INPUT-OUTPUT PARAMETER ligne    AS   CHARACTER        NO-UNDO.
DEF VAR i          AS   INTEGER                    NO-UNDO.

DO i = 1 TO nombre:
   IF INDEX(tag,ancre + STRING(i,"99")) <> 0 THEN ligne = REPLACE(ligne,tag,ENTRY(i,texte,"#")).
END.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE suppression_ligne w-html 
PROCEDURE suppression_ligne :
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/

{supprime_ligne.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

